package com.zucc.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class RailwayConfiguration {

    /**
     * 统一返回值封装
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(RespAdvice.class)
    public RespAdvice RailwayFacadeServerResponseWrapperControllerAdvice() {
        log.info("init RailwayFacadeServerResponseWrapperControllerAdvice");
        return new RespAdvice();
    }

    /**
     * 统一异常处理
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(ExceptionAdvice.class)
    public ExceptionAdvice RailwayFacadeServerExceptionHandlerControllerAdvice() {
        log.info("init RailwayFacadeServerExceptionHandlerControllerAdvice");
        return new ExceptionAdvice();
    }

//    /**
//     * 登录检查
//     *
//     * @return
//     */
//    @Bean
//    @ConditionalOnMissingBean(RailwayFacadeServerCheckLoginInterceptor.class)
//    public RailwayFacadeServerCheckLoginInterceptor bbuCloudCheckLoginInterceptor() {
//        log.info("init RailwayFacadeServerCheckLoginInterceptor in");
//        return new RailwayFacadeServerCheckLoginInterceptor();
//    }



    /**
     * 对返回的是数据的时间进行处理
     *
     * @return
     */
//    @Bean
//    public HttpMessageConverters customConverters() {
//        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
//        // 创建配置类
//        FastJsonConfig config = new FastJsonConfig();
//        config.setSerializerFeatures(
//                SerializerFeature.WriteNullListAsEmpty,
//                SerializerFeature.WriteMapNullValue,
//                SerializerFeature.WriteNullStringAsEmpty
//        );
//
//        //此处是全局处理方式
//        config.setDateFormat("yyyy-MM-dd HH:mm:ss");
//        config.setCharset(Charset.forName("UTF-8"));
//        fastConverter.setFastJsonConfig(config);
//
//        List<MediaType> supportedMediaTypes = new ArrayList<>();
//        supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
//        fastConverter.setSupportedMediaTypes(supportedMediaTypes);
//        //支持text 转string
//        StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
//        return new HttpMessageConverters(fastConverter, stringHttpMessageConverter);
//    }
//    @Bean
//    @ConditionalOnMissingBean({WebConfig.class})
//    public WebConfig jijueCloudFeignWebConfig() {
//        log.info("init WebConfig");
//        return new WebConfig();
//    }

}
